package games.Mexen;


public class Speler implements SpelerImpl {
	private String naam;
	private int punten = 6, score = 0;
	private DobbelsteenImpl steen1, steen2;

	public Speler() {
		
	}
	
	public Speler(String naam, DobbelsteenImpl steen1, DobbelsteenImpl steen2) {
		setUp(naam, steen1, steen2);
	}

	/* (non-Javadoc)
	 * @see games.Mexen.SpelerImp#getNaam()
	 */
	@Override
	public synchronized String getNaam() {
		return naam;
	}

	/* (non-Javadoc)
	 * @see games.Mexen.SpelerImp#getScore()
	 */
	@Override
	public synchronized int getScore() {
		return score;
	}

	/* (non-Javadoc)
	 * @see games.Mexen.SpelerImp#getPunten()
	 */
	@Override
	public synchronized int getPunten() {
		return punten;
	}
	
	/* (non-Javadoc)
	 * @see games.Mexen.SpelerImp#minderPunten(int)
	 */
	@Override
	public synchronized void minderPunten(int minPunten) {
		punten -= minPunten;
	}

	/* (non-Javadoc)
	 * @see games.Mexen.SpelerImp#werp()
	 */
	@Override
	public synchronized void werp() {
		steen1.werp();
		steen2.werp();
		berekenScore();
	}

	private synchronized void berekenScore() {
		score = 0;
		int w1 = steen1.getWorp();
		int w2 = steen2.getWorp();

		if (w1 > w2) {
			score = (w1*10) + w2;
		} else
		if (w1 < w2) {
			score = w1 + (w2 * 10);
		}else 
		if (w1 == w2) {
			score = (w1*100);
		}
		
		//mex
		if(score == 21) {
			score = 1000;
		}
	}
	
	public synchronized String toString() {
		return naam;
	}

	/* (non-Javadoc)
	 * @see games.Mexen.SpelerImp#setScore(int)
	 */
	@Override
	public synchronized void setScore(int i) {
		score = i;
	}

	@Override
	public void setUp(String naam, DobbelsteenImpl steen1,
			DobbelsteenImpl steen2) {
		this.naam = naam;
		this.steen1 = steen1;
		this.steen2 = steen2;	
	}
}
